package com.zt.dao.base;

import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.StatementCallback;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.rowset.SqlRowSet;

import com.zt.dao.support.Page;

/**
 * DAO接口 IBaseDao
 * 
 * @author zhangzhw 所有Dao接口继承此接口
 */
public interface IBaseDao {

	/**
	 * 方法 pagingFind
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @return 分页查询返回PageInfo (分页内的数据对象List 和 总数据数)
	 */
	public abstract <X> Page<X> pagingFind(String sql, long start, long limit,
			RowMapper rowMapper);

	/**
	 * 方法 pagingFind
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @return 分页查询返回PageInfo (分页内的数据对象List 和 总数据数)
	 */
	public abstract <X> Page<X> pagingFind(Page<X> pi, String sql, long start,
			long limit, RowMapper rowMapper);

	/**
	 * 方法 pagingFind
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @param obj
	 * @return 单条件分页查询返回PageInfo (分页内的数据对象List 和 总数据数)
	 */
	@SuppressWarnings("unchecked")
	public abstract <X> Page<X> pagingFind(String sql, long start, long limit,
			RowMapper rowMapper, Object obj);

	/**
	 * 重写分页查询，修改上面分页方式在Action层无法确定每页显示条数的BUG
	 * 
	 * @param <X>
	 * @param pi
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @param obj
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public abstract <X> Page<X> pagingFind(Page<X> pi, String sql, long start,
			long limit, RowMapper rowMapper, Object[] obj);

	/**
	 * 方法 pagingFind
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @param obj
	 * @return 按条件分页查询返回PageInfo (分页内的数据对象List 和 总数据数)
	 */
	@SuppressWarnings("unchecked")
	public abstract <X> Page<X> pagingFind(String sql, long start, long limit,
			RowMapper rowMapper, Object[] obj);

	/**
	 * 方法 pagingFindList
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @return 分页查询的记录对象
	 */
	public abstract <X> List<X> pagingFindList(String sql, long start,
			long limit, RowMapper rowMapper);

	/**
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @param obj
	 * @return 分页查询的记录对象(单一条件查询)
	 */
	@SuppressWarnings("unchecked")
	public abstract <X> List<X> pagingFindList(String sql, long start,
			long limit, RowMapper rowMapper, Object obj);

	/**
	 * 方法 pagingFindList
	 * 
	 * @param sql
	 * @param start
	 * @param limit
	 * @param rowMapper
	 * @param obj
	 * @return 条件查询分页查询的记录对象
	 */
	@SuppressWarnings("unchecked")
	public abstract <X> List<X> pagingFindList(String sql, long start,
			long limit, RowMapper rowMapper, Object[] obj);

	/**
	 * 方法 pagingFindCount
	 * 
	 * @param sql
	 * @return 该sql语句能查询到的记录总数
	 */
	public abstract long pagingFindCount(String sql);

	/**
	 * 方法 pagingFindCount
	 * 
	 * @param sql
	 * @param obj
	 * @return 该sql语句能查询到的记录总数
	 */
	public abstract long pagingFindCount(String sql, Object obj);

	/**
	 * 方法 pagingFindCount
	 * 
	 * @param sql
	 * @param obj
	 * @return 条件查询记录总数
	 */
	public abstract long pagingFindCount(String sql, Object[] obj);

	// ----------------------------------------------------------------------

	// 以下为JdbcTemplate的方法
	public abstract int[] batchUpdate(String sql,
			BatchPreparedStatementSetter pss) throws DataAccessException;

	public abstract int[] batchUpdate(String[] sql) throws DataAccessException;

	public abstract Map<String, Object> call(CallableStatementCreator csc,
			List<SqlParameter> declaredParameters) throws DataAccessException;

	public abstract <T> T execute(CallableStatementCreator csc,
			CallableStatementCallback<T> action) throws DataAccessException;

	public abstract <T> T execute(ConnectionCallback<T> action)
			throws DataAccessException;

	public abstract <T> T execute(PreparedStatementCreator psc,
			PreparedStatementCallback<T> action) throws DataAccessException;

	public abstract <T> T execute(StatementCallback<T> action)
			throws DataAccessException;

	public abstract <T> T execute(String callString,
			CallableStatementCallback<T> action) throws DataAccessException;

	public abstract <T> T execute(String sql,
			PreparedStatementCallback<T> action) throws DataAccessException;

	public abstract void execute(String sql) throws DataAccessException;

	public abstract int getFetchSize();

	public abstract int getMaxRows();

	public abstract NativeJdbcExtractor getNativeJdbcExtractor();

	public abstract int getQueryTimeout();

	public abstract boolean isIgnoreWarnings();

	public abstract boolean isResultsMapCaseInsensitive();

	public abstract boolean isSkipResultsProcessing();

	public abstract boolean isSkipUndeclaredResults();

	public abstract <T> T query(PreparedStatementCreator psc,
			PreparedStatementSetter pss, ResultSetExtractor<T> rse)
			throws DataAccessException;

	public abstract <T> T query(PreparedStatementCreator psc,
			ResultSetExtractor<T> rse) throws DataAccessException;

	public abstract void query(PreparedStatementCreator psc,
			RowCallbackHandler rch) throws DataAccessException;

	public abstract <T> List<T> query(PreparedStatementCreator psc,
			RowMapper<T> rowMapper) throws DataAccessException;

	public abstract <T> T query(String sql, Object[] args, int[] argTypes,
			ResultSetExtractor<T> rse) throws DataAccessException;

	public abstract void query(String sql, Object[] args, int[] argTypes,
			RowCallbackHandler rch) throws DataAccessException;

	public abstract <T> List<T> query(String sql, Object[] args,
			int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException;

	public abstract <T> T query(String sql, Object[] args,
			ResultSetExtractor<T> rse) throws DataAccessException;

	public abstract void query(String sql, Object[] args, RowCallbackHandler rch)
			throws DataAccessException;

	public abstract <T> List<T> query(String sql, Object[] args,
			RowMapper<T> rowMapper) throws DataAccessException;

	public abstract <T> T query(String sql, PreparedStatementSetter pss,
			ResultSetExtractor<T> rse) throws DataAccessException;

	public abstract void query(String sql, PreparedStatementSetter pss,
			RowCallbackHandler rch) throws DataAccessException;

	public abstract <T> List<T> query(String sql, PreparedStatementSetter pss,
			RowMapper<T> rowMapper) throws DataAccessException;

	public abstract <T> T query(String sql, ResultSetExtractor<T> rse,
			Object... args) throws DataAccessException;

	public abstract <T> T query(String sql, ResultSetExtractor<T> rse)
			throws DataAccessException;

	public abstract void query(String sql, RowCallbackHandler rch,
			Object... args) throws DataAccessException;

	public abstract void query(String sql, RowCallbackHandler rch)
			throws DataAccessException;

	public abstract <T> List<T> query(String sql, RowMapper<T> rowMapper,
			Object... args) throws DataAccessException;

	public abstract <T> List<T> query(String sql, RowMapper<T> rowMapper)
			throws DataAccessException;

	public abstract int queryForInt(String sql, Object... args)
			throws DataAccessException;

	public abstract int queryForInt(String sql, Object[] args, int[] argTypes)
			throws DataAccessException;

	public abstract int queryForInt(String sql) throws DataAccessException;

	public abstract <T> List<T> queryForList(String sql, Class<T> elementType,
			Object... args) throws DataAccessException;

	public abstract <T> List<T> queryForList(String sql, Class<T> elementType)
			throws DataAccessException;

	public abstract List<Map<String, Object>> queryForList(String sql,
			Object... args) throws DataAccessException;

	public abstract <T> List<T> queryForList(String sql, Object[] args,
			Class<T> elementType) throws DataAccessException;

	public abstract <T> List<T> queryForList(String sql, Object[] args,
			int[] argTypes, Class<T> elementType) throws DataAccessException;

	public abstract List<Map<String, Object>> queryForList(String sql,
			Object[] args, int[] argTypes) throws DataAccessException;

	public abstract List<Map<String, Object>> queryForList(String sql)
			throws DataAccessException;

	public abstract long queryForLong(String sql, Object... args)
			throws DataAccessException;

	public abstract long queryForLong(String sql, Object[] args, int[] argTypes)
			throws DataAccessException;

	public abstract long queryForLong(String sql) throws DataAccessException;

	public abstract Map<String, Object> queryForMap(String sql, Object... args)
			throws DataAccessException;

	public abstract Map<String, Object> queryForMap(String sql, Object[] args,
			int[] argTypes) throws DataAccessException;

	public abstract Map<String, Object> queryForMap(String sql)
			throws DataAccessException;

	public abstract <T> T queryForObject(String sql, Class<T> requiredType,
			Object... args) throws DataAccessException;

	public abstract <T> T queryForObject(String sql, Class<T> requiredType)
			throws DataAccessException;

	public abstract <T> T queryForObject(String sql, Object[] args,
			Class<T> requiredType) throws DataAccessException;

	public abstract <T> T queryForObject(String sql, Object[] args,
			int[] argTypes, Class<T> requiredType) throws DataAccessException;

	public abstract <T> T queryForObject(String sql, Object[] args,
			int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException;

	public abstract <T> T queryForObject(String sql, Object[] args,
			RowMapper<T> rowMapper) throws DataAccessException;

	public abstract <T> T queryForObject(String sql, RowMapper<T> rowMapper,
			Object... args) throws DataAccessException;

	public abstract <T> T queryForObject(String sql, RowMapper<T> rowMapper)
			throws DataAccessException;

	public abstract SqlRowSet queryForRowSet(String sql, Object... args)
			throws DataAccessException;

	public abstract SqlRowSet queryForRowSet(String sql, Object[] args,
			int[] argTypes) throws DataAccessException;

	public abstract SqlRowSet queryForRowSet(String sql)
			throws DataAccessException;

	public abstract void setFetchSize(int fetchSize);

	public abstract void setIgnoreWarnings(boolean ignoreWarnings);

	public abstract void setMaxRows(int maxRows);

	public abstract void setNativeJdbcExtractor(NativeJdbcExtractor extractor);

	public abstract void setQueryTimeout(int queryTimeout);

	public abstract void setResultsMapCaseInsensitive(
			boolean resultsMapCaseInsensitive);

	public abstract void setSkipResultsProcessing(boolean skipResultsProcessing);

	public abstract void setSkipUndeclaredResults(boolean skipUndeclaredResults);

	public abstract int update(PreparedStatementCreator psc,
			KeyHolder generatedKeyHolder) throws DataAccessException;

	public abstract int update(PreparedStatementCreator psc)
			throws DataAccessException;

	public abstract int update(String sql, Object... args)
			throws DataAccessException;

	public abstract int update(String sql, Object[] args, int[] argTypes)
			throws DataAccessException;

	public abstract int update(String sql, PreparedStatementSetter pss)
			throws DataAccessException;

	public abstract int update(String sql) throws DataAccessException;
}
